package com.rzico.basics.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.math.BigDecimal;
import java.util.Date;

/**
 * <pre>
 *   大转盘记录数据库对象
 * </pre>
 *
 * @author Rzico Boot
 * @version 1.0
 */
@Data
@JsonIgnoreProperties(value = {"handler"})
@JsonInclude(JsonInclude.Include.NON_NULL)
@Table(name = "wx_turntable_record")
public class TurntableRecord {

    @Id
    @ApiModelProperty
    protected Long id;

    @ApiModelProperty(value = "大转盘ID")
    protected Long turntableId;

    @ApiModelProperty(value = "会员ID")
    protected Long memberId;

    @ApiModelProperty(value = "联系电话")
    protected String phone;

    @ApiModelProperty(value = "联系地址")
    protected String address;

    @ApiModelProperty(value = "参与时间")
    protected Date scratchTime;

    @ApiModelProperty(value = "参与时间的数字格式，只用于比较")
    protected Integer scratchTimeInt;

    @ApiModelProperty(value = "参与结果 0-未中奖 1-中奖")
    protected Integer scratchResult;

    @ApiModelProperty(value = "参与结果描述")
    protected String resultRemark;

    @ApiModelProperty(value = "奖品ID")
    protected Long prizeId;

    @ApiModelProperty(value = "是否已领取奖品 0-未领取 1-已领取")
    protected Integer isDraw;

    @ApiModelProperty(value = "是否已使用 0-未使用 1-已使用")
    protected Integer isUsed;

    @ApiModelProperty(value = "奖品关联ID：如优惠券则是coupon_code_id")
    protected Long relationId;

    @ApiModelProperty(value = "奖品名称")
    protected String prizeName;

    @ApiModelProperty(value = "会员")
    @JsonIgnore
    protected Member member;

    @Transient
    protected BigDecimal angle;

    /**
     * 获取 会员名称
     */
    public String getMemberName() {
        Member member = getMember();
        if (member != null) return member.getName();
        return null;
    }

    public void setMemberName(String memberName) {

    }

    /**
     * 获取 会员手机号
     */
    public String getMemberMobile() {
        Member member = getMember();
        if (member != null) return member.getMobile();
        return null;
    }

    public void setMemberMobile(String memberMobile) {

    }

    public String getEncryMobile() {
        Member member = getMember();
        if (member != null) return member.getMobile().replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1*****$2");
        return null;
    }

    public void setEncryMobile(String encryMobile) {

    }

}
